package com.yenlien.traceyun.control.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.entity.Log;
import com.yenlien.traceyun.control.service.LogService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/log")
public class LogController extends BaseController {

    @Autowired
    private LogService logService;

    /**
     * 查询日志
     *
     * @param params
     * @return
     */
    @PostMapping("/inquire")
    private Object inquire(@RequestBody JSONObject params) {
        Integer page = params.getInteger("page");
        if (page > 0) {
            Integer page1 = page - 1;
            return buildPage(logService.select(page1));
        } else {
            return fail("页面加载错误");
        }
    }

    /**
     * 搜索栏(模糊查询)
     *
     * @param params
     * @return
     */
    @PostMapping("/search")
    public Object search(@RequestBody JSONObject params) {
        Log log = params.getObject("log", Log.class);
        return success(logService.search(log));
    }

    /**
     * 获取日志的所有操作类型
     *
     * @return
     */
    @GetMapping("/getOperation")
    public Object getOperation() {
        return success(logService.getOperation());
    }


    /**
     * 查询30天内的活跃用户
     *
     * @return
     */
    @PostMapping("/userActivation")
    public Object userActivation() {
        return success(logService.userActivation());
    }

    /**
     * 查询30天内活跃的企业
     *
     * @return
     */
    @PostMapping("/companyActivation")
    public Object companyActivation() {
        return success(logService.companyActivation());
    }


}
